<?php
	include "layout.php";
	head();
	if (!isset($_SESSION["id"])) {
		header("Location: index.php");
	}
	if (isset($_SESSION["oid"])) {
		header("Location: cust.php");
	}
?>
<?php

	if (isset($_GET["sub1"])) {
		extract($_GET);
		$queryb = mysql_query("SELECT * FROM blconfig,items WHERE blconfig.BLConfig_Description='{$baseline}' AND items.Items_ID = blconfig.B_Items_ID AND Item_Cat = 'B'");
		$queryc = mysql_query("SELECT * FROM blconfig,items WHERE blconfig.BLConfig_Description='{$baseline}' AND items.Items_ID = blconfig.B_Items_ID AND Item_Cat = 'C'");
		$queryg = mysql_query("SELECT * FROM blconfig,items WHERE blconfig.BLConfig_Description='{$baseline}' AND items.Items_ID = blconfig.B_Items_ID AND Item_Cat = 'G'");
		$queryh = mysql_query("SELECT * FROM blconfig,items WHERE blconfig.BLConfig_Description='{$baseline}' AND items.Items_ID = blconfig.B_Items_ID AND Item_Cat = 'H'");
?>
<h4 style="text-align: center;"><?php echo $baseline; ?> Configuration</h4>
<h5>Baked Goods</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th>Item Name</th>
		<th>Item Category</th>
	</tr>
<?php
		while ($baked = mysql_fetch_array($queryb)) {
			extract($baked);
			echo <<<Baked
	<tr>
		<td>{$Items_Description}</td>
		<td>Baked Goods</td>
	</tr>
Baked;
		}
?>
</table>
<br />
<h5>Chips</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th>Item Name</th>
		<th>Item Category</th>
	</tr>
<?php
		while ($chips = mysql_fetch_array($queryc)) {
			extract($chips);
			echo <<<Chips
	<tr>
		<td>{$Items_Description}</td>
		<td>Chips</td>
	</tr>
Chips;
		}
?>
</table>
<br />
<h5>Gum</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th>Item Name</th>
		<th>Item Category</th>
	</tr>
<?php
		while ($gum = mysql_fetch_array($queryg)) {
			extract($gum);
			echo <<<Gum
	<tr>
		<td>{$Items_Description}</td>
		<td>Gum</td>
	</tr>
Gum;
		}
?>
</table>
<br />
<h5>Healthy Alternatives</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th>Item Name</th>
		<th>Item Category</th>
	</tr>
<?php
		while ($healthy = mysql_fetch_array($queryh)) {
			extract($healthy);
			echo <<<Healthy
	<tr>
		<td>{$Items_Description}</td>
		<td>Healthy Alternative</td>
	</tr>
Healthy;
		}
?>
</table>
<form method="post" action="base.php" style="text-align: center">
	<div class="form_settings">
		<p style="text-align: center;">Are you okay with this Baseline Configuration?</p>
		<input type="hidden" name="baseline" value="<?php echo $baseline; ?>" />
		<input type="submit" class="submit" name="sub2" style="margin-left: 0px;" value="Yes" />
		<input type="submit" class="submit" name="sub2" style="margin-left: 33px;" value="No" />
	</div>
</form>
<?php
	}
	else if (isset($_POST["sub2"])) {
		extract($_POST);
		if ($sub2 == "Yes") {
			$id = $_SESSION["id"];
			$date = date("Y-m-d");
			mysql_query("INSERT INTO orderacc VALUES(NULL, {$id}, '{$date}')");
			$query = mysql_query("SELECT * FROM orderacc WHERE OA_Cust_ID = {$id} ORDER BY OrderAcc_Date DESC");
			$result = mysql_fetch_array($query);
			$_SESSION["oid"] = $result["OrderAcc_ID"];
			$oid = $_SESSION["oid"];
			$q = mysql_query("SELECT * FROM blconfig WHERE BLConfig_Description = '{$baseline}'");
			while ($rows = mysql_fetch_array($q)) {
				extract($rows);
				mysql_query("INSERT INTO oa_items VALUES({$oid}, {$B_Items_ID}, '{$date}')");
			}
			header("Location: cust.php");
		}
		else {
			header("Location: base.php");
		}
	}
	else {
?>
<h4 style="text-align: center;">Select a Baseline Inventory</h4>
<form action="base.php" method="get">
	<div class="form_settings">
		<p>
			<span>Select a Baseline Configuration</span>
			<select name="baseline">
				<option value="">Please Select One</option>
				<option value="Baseline #1">Baseline #1</option>
				<option value="Baseline #2">Baseline #2</option>
			</select>
		</p>
		<p style="padding-top:15px">
			<span>&nbsp;</span>
			<input class="submit" type="submit" name="sub1" value="Submit">
		</p>
	</div>
</form>
<?php
	}
?>
<?php
	foot();
?>